import PlayerDataSys from "./PlayerDataSys";
import PeripheralSystemDataMgr from "./PeripheralSystemDataMgr";
import EventMgr from "./EventMgr";
import GameEventType from "./GameEventType";
import frameworkManager from "./frameworkManager";
import SdkHelper from "./SdkHelper";
import EngineUtil from "./EngineUtil";
import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import PeripheralSystemMgr from "./PeripheralSystemMgr";
import UiManage from "./UiManage";
import NotclaimedRewardPage from "./NotclaimedRewardPage";

const { ccclass, property } = cc._decorator;

@ccclass
export default class NotclaimedRewardPageCtrl extends BasePageCtrl {
    @property(NotclaimedRewardPage)
    ui = null;

    onLoad() {
        super.onLoad();
        this._animType = AnimType.SCALE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = true;
        this._hasBlackTouch = false;
        this.onUILoad();
        this.addButtonListen();
    };

    start() { };

    _init() {
        var e = PeripheralSystemDataMgr.getYesClockData();
        if (e) {
            var t = e.reward;
            var a = e.reward_type;
            var o = "reward_" + a;
            UiManage.loadSpriteFrame(this.ui.reward, "notclaimedReward", o);
            this.ui.count.getComponent(cc.Label).string = a === 1 ? EngineUtil.getCashBalance(t) + "元" : "x" + t;
        } else {
            frameworkManager.log("没有获取到==昨日打卡数据=======");
        }
    };

    onUILoad() {
        this.ui = this.node.addComponent(NotclaimedRewardPage);
    };

    addButtonListen() {
        UiManage.addButtonListen(this.ui.btn_receive, this.clickReceive, this);
    };

    clickReceive() {
        var e = this;
        var t = PeripheralSystemDataMgr.getYesClockData();
        var a = t.reward;
        var o = t.reward_type;
        var i = t.task_id;
        PeripheralSystemMgr.getClockTaskReward(i, 1, function (t) {
            if (t && t.clock_days >= 30) {
                SdkHelper.reportData("clock_day_success_2", { days: 30 });
                EventMgr.trigger(GameEventType.SHOW_BEIJING_FLAG_ANI);
                e.clickClose();
            } else {
                var i;
                i = o === 1 ? 0 : o;
                EventMgr.trigger(GameEventType.SHOWEFFECT_FLYINGRED, {
                    startPos: e.ui.reward.getPosition(),
                    type: i,
                    callback: function () {
                        if (o === 1) {
                            PlayerDataSys.updateCashBalace(a);
                        }
                    },
                    reward: a
                });
                e.hide();
            }
        });
    };

    clickClose() {
        this.hide();
    };
}
